package com.profiloc.ui.custom;

import net.rim.device.api.lbs.MapField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYPoint;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.Dialog;

public class CustomMapField extends MapField{

	/*
	 * Custom mapfield class so that you can
	 * place marker in the paint method 
	 * of the orginal map field class
	 */
	
	private Bitmap marker;
	private XYRect markerRect;
	
	protected void paint(Graphics graphics) {

		super.paint(graphics);
		marker = Bitmap.getBitmapResource("chart.png");
			
		if(marker != null){
			
			// Place a cursor permanently at the center of the map.
	        int width = getPreferredWidth();
	        int height = getPreferredHeight();
	        graphics.drawBitmap((width/2), (height/2), width, height, marker, 0, 0);
	         
	        XYPoint markerPoint = new XYPoint();
	        convertWorldToField(getCoordinates(), markerPoint);
	        int markerW = marker.getWidth();
	        int markerH = marker.getHeight();
	        
	        markerRect = new XYRect(markerPoint.x,markerPoint.y, markerW,markerH);
	        graphics.drawBitmap(markerRect, marker, 0, 0);
		}else{
			
			Dialog.alert("Can not load merker image");
		}
	        
		 
	}
}
